{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "demo.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "06efggt8NzHk",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PGqJeQl3N_rR",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from sklearn.linear_model import LogisticRegression\n",
        "from sklearn.datasets import load_iris\n",
        "from sklearn.model_selection import train_test_split\n",
        "\n",
        "# Load and split data\n",
        "data = load_iris()\n",
        "Xtrain, Xtest, Ytrain, Ytest = train_test_split(data.data, data.target, test_size=0.3, random_state=4)"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QsMjBwEXOrSN",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 162
        },
        "outputId": "2352c9bf-89cd-476c-8643-1e6cd8cef5a6"
      },
      "source": [
        "# Create a model\n",
        "model = LogisticRegression(C=0.1, \n",
        "                           max_iter=20, \n",
        "                           fit_intercept=True, \n",
        "                           n_jobs=3, \n",
        "                           solver='liblinear')\n",
        "model.fit(Xtrain, Ytrain)"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/_logistic.py:1539: UserWarning: 'n_jobs' > 1 does not have any effect when 'solver' is set to 'liblinear'. Got 'n_jobs' = 3.\n",
            "  \" = {}.\".format(effective_n_jobs(self.n_jobs)))\n"
          ],
          "name": "stderr"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "LogisticRegression(C=0.1, class_weight=None, dual=False, fit_intercept=True,\n",
              "                   intercept_scaling=1, l1_ratio=None, max_iter=20,\n",
              "                   multi_class='auto', n_jobs=3, penalty='l2',\n",
              "                   random_state=None, solver='liblinear', tol=0.0001, verbose=0,\n",
              "                   warm_start=False)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EsY-Z1CSOx55",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "d9eb4582-6bd8-4208-c15e-ec654d7ef0fd"
      },
      "source": [
        "import pickle\n",
        "\n",
        "#\n",
        "# Create your model here (same as above)\n",
        "#\n",
        "\n",
        "# Save to file in the current working directory\n",
        "pkl_filename = \"pickle_model.pkl\"\n",
        "with open(pkl_filename, 'wb') as file:\n",
        "    pickle.dump(model, file)\n",
        "\n",
        "# Load from file\n",
        "with open(pkl_filename, 'rb') as file:\n",
        "    pickle_model = pickle.load(file)\n",
        "    \n",
        "# Calculate the accuracy score and predict target values\n",
        "score = pickle_model.score(Xtest, Ytest)\n",
        "print(\"Test score: {0:.2f} %\".format(100 * score))\n",
        "Ypredict = pickle_model.predict(Xtest)"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Test score: 91.11 %\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EiIinOYtO3ix",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 5,
      "outputs": []
    }
  ]
}
